//package com.yoomiito.app.ui.video
//
//import android.graphics.SurfaceTexture
//import android.media.AudioManager
//import android.os.Handler
//import android.os.HandlerThread
//import android.view.Surface
//
//import java.io.IOException
//
//import cn.jzvd.JZMediaInterface
//import cn.jzvd.Jzvd
//import tv.danmaku.ijk.media.player.IMediaPlayer
//import tv.danmaku.ijk.media.player.IjkMediaPlayer
//import tv.danmaku.ijk.media.player.IjkTimedText
//
//class JZMediaIjk(jzvd: Jzvd) : JZMediaInterface(jzvd), IMediaPlayer.OnPreparedListener, IMediaPlayer.OnVideoSizeChangedListener, IMediaPlayer.OnCompletionListener, IMediaPlayer.OnErrorListener, IMediaPlayer.OnInfoListener, IMediaPlayer.OnBufferingUpdateListener, IMediaPlayer.OnSeekCompleteListener, IMediaPlayer.OnTimedTextListener {
//    internal var ijkMediaPlayer: IjkMediaPlayer? = null
//
//    override fun start() {
//        if (ijkMediaPlayer != null) ijkMediaPlayer!!.start()
//    }
//
//    override fun prepare() {
//
//        release()
//        mMediaHandlerThread = HandlerThread("JZVD")
//        mMediaHandlerThread.start()
//        mMediaHandler = Handler(mMediaHandlerThread.looper)//主线程还是非主线程，就在这里
//        handler = Handler()
//
//        mMediaHandler.post {
//
//            ijkMediaPlayer = IjkMediaPlayer()
//            ijkMediaPlayer!!.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 0)
//            ijkMediaPlayer!!.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "opensles", 0)
//            ijkMediaPlayer!!.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", IjkMediaPlayer.SDL_FCC_RV32.toLong())
//            ijkMediaPlayer!!.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 1)
//            ijkMediaPlayer!!.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0)
//            ijkMediaPlayer!!.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "http-detect-range-support", 0)
//            ijkMediaPlayer!!.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48)
//            ijkMediaPlayer!!.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-buffer-size", (1024 * 1024).toLong())
//            ijkMediaPlayer!!.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", 1)
//
//            ijkMediaPlayer!!.setOnPreparedListener(this@JZMediaIjk)
//            ijkMediaPlayer!!.setOnVideoSizeChangedListener(this@JZMediaIjk)
//            ijkMediaPlayer!!.setOnCompletionListener(this@JZMediaIjk)
//            ijkMediaPlayer!!.setOnErrorListener(this@JZMediaIjk)
//            ijkMediaPlayer!!.setOnInfoListener(this@JZMediaIjk)
//            ijkMediaPlayer!!.setOnBufferingUpdateListener(this@JZMediaIjk)
//            ijkMediaPlayer!!.setOnSeekCompleteListener(this@JZMediaIjk)
//            ijkMediaPlayer!!.setOnTimedTextListener(this@JZMediaIjk)
//
//            try {
//                ijkMediaPlayer!!.dataSource = jzvd.jzDataSource.currentUrl.toString()
//                ijkMediaPlayer!!.setAudioStreamType(AudioManager.STREAM_MUSIC)
//                ijkMediaPlayer!!.setScreenOnWhilePlaying(true)
//                ijkMediaPlayer!!.prepareAsync()
//
//                ijkMediaPlayer!!.setSurface(Surface(jzvd.textureView.surfaceTexture))
//            } catch (e: IOException) {
//                e.printStackTrace()
//            }
//        }
//
//    }
//
//    override fun pause() {
//        ijkMediaPlayer!!.pause()
//    }
//
//    override fun isPlaying(): Boolean {
//        return ijkMediaPlayer!!.isPlaying
//    }
//
//    override fun seekTo(time: Long) {
//        ijkMediaPlayer!!.seekTo(time)
//    }
//
//    override fun release() {
//        if (mMediaHandler != null && mMediaHandlerThread != null && ijkMediaPlayer != null) {//不知道有没有妖孽
//            val tmpHandlerThread = mMediaHandlerThread
//            val tmpMediaPlayer = ijkMediaPlayer
//            JZMediaInterface.SAVED_SURFACE = null
//
//            mMediaHandler.post {
//                tmpMediaPlayer!!.setSurface(null)
//                tmpMediaPlayer.release()
//                tmpHandlerThread.quit()
//            }
//            ijkMediaPlayer = null
//        }
//    }
//
//    override fun getCurrentPosition(): Long {
//        return ijkMediaPlayer!!.currentPosition
//    }
//
//    override fun getDuration(): Long {
//        return ijkMediaPlayer!!.duration
//    }
//
//    override fun setVolume(leftVolume: Float, rightVolume: Float) {
//        ijkMediaPlayer!!.setVolume(leftVolume, rightVolume)
//    }
//
//    override fun setSpeed(speed: Float) {
//        ijkMediaPlayer!!.setSpeed(speed)
//    }
//
//    override fun onPrepared(iMediaPlayer: IMediaPlayer) {
//        handler.post { jzvd.onPrepared() }
//    }
//
//    override fun onVideoSizeChanged(iMediaPlayer: IMediaPlayer, i: Int, i1: Int, i2: Int, i3: Int) {
//        handler.post { jzvd.onVideoSizeChanged(iMediaPlayer.videoWidth, iMediaPlayer.videoHeight) }
//    }
//
//    override fun onError(iMediaPlayer: IMediaPlayer, what: Int, extra: Int): Boolean {
//        handler.post { jzvd.onError(what, extra) }
//        return true
//    }
//
//    override fun onInfo(iMediaPlayer: IMediaPlayer, what: Int, extra: Int): Boolean {
//        handler.post { jzvd.onInfo(what, extra) }
//        return false
//    }
//
//    override fun onBufferingUpdate(iMediaPlayer: IMediaPlayer, percent: Int) {
//        handler.post { jzvd.setBufferProgress(percent) }
//    }
//
//    override fun onSeekComplete(iMediaPlayer: IMediaPlayer) {
//        handler.post { jzvd.onSeekComplete() }
//    }
//
//    override fun onTimedText(iMediaPlayer: IMediaPlayer, ijkTimedText: IjkTimedText) {
//
//    }
//
//    override fun setSurface(surface: Surface) {
//        ijkMediaPlayer!!.setSurface(surface)
//    }
//
//    override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int) {
//        if (JZMediaInterface.SAVED_SURFACE == null) {
//            JZMediaInterface.SAVED_SURFACE = surface
//            prepare()
//        } else {
//            jzvd.textureView.surfaceTexture = JZMediaInterface.SAVED_SURFACE
//        }
//    }
//
//    override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) {
//
//    }
//
//    override fun onSurfaceTextureDestroyed(surface: SurfaceTexture): Boolean {
//        return false
//    }
//
//    override fun onSurfaceTextureUpdated(surface: SurfaceTexture) {
//
//    }
//
//    override fun onCompletion(iMediaPlayer: IMediaPlayer) {
//        handler.post { jzvd.onAutoCompletion() }
//    }
//
//}
